<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Menu extends CI_Controller{
	public function index()
	{
		$appid = $this->config->item('appid');
		$secret = $this->config->item('appsecret');
		$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";

		//使用menu_helper中的 https_request方法,获取到token
		$json_info = json_decode(https_request($url),true);
		$access_token = $json_info['access_token'];
		$jsonmenu='{
			    "button": [
			        {
			            "name": "快速回复", 
			            "sub_button": [
			                {
			                    "type": "click", 
			                    "name": "我的课程", 
			                    "key": "course"
			                }, 
			                {
			                    "type": "click", 
			                    "name": "个人信息", 
			                    "key": "info"
			                },
			                {
			                	"type": "click", 
			                    "name": "考勤信息", 
			                    "key": "kaoqin"
			                },
			                {
			                	"type": "click", 
			                    "name": "考试时间", 
			                    "key": "time"
			                }
			            ]
			        }, 
			        {
			            "name": "记录", 
			            "sub_button": [
			                {
			                    "type": "click", 
			                    "name": "奖励记录", 
			                    "key" : "reward" 
			                 }, 
			                {
			                    "type":"click",
								"name":"成绩",
								"key" : "score"	
			                }, 
			                {
			                    "type":"click",
								"name":"违规记录",
								"key" : "illegal"
			                }
			            ]
			        }, 
			        {
			            "name": "其他功能", 
			            "sub_button": [
			                {
			                    "type": "click", 
			                    "name": "绑定", 
			                    "key" : "bind"
			                 }, 
			                {
			                    "type":"click",
								"name":"解除绑定",
								"key" : "unbind"	
			                }, 
			                {
			                    "type":"view",
								"name":"关于我们",
								"url" : "http://www.baidu.com" 
			                },
			                {
			                	"type":"view",
								"name":"留言板",
								"url" : "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe65fd69d2da5b545&redirect_uri=http://mysise.duapp.com/index.php/comment/index&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect" 
			                }
			            ]
			        }
			       
			    ]
			}';
	$url="https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
	$result=https_request($url,$jsonmenu);
	var_dump($result);
	}
}